#define _CRT_SECURE_NO_WARNINGS 1

#include <string>
using namespace std;

class Solution {
public:

    string addStrings(string num1, string num2) {
        string ret;
        int n1 = num1.size() - 1;
        int n2 = num2.size() - 1;
        int carry = 0;
        while (n1 >= 0 || n2 >= 0)
        {
            int d1 = n1 >= 0 ? num1[n1] - '0' : 0;
            int d2 = n2 >= 0 ? num2[n2] - '0' : 0;
            ret += ((d1 + d2 + carry) % 10 + '0');
            carry = (d1 + d2 + carry) / 10;
            //cout<<ret<<endl;
            --n1;
            --n2;
        }
        if (carry != 0)
            ret += (carry + '0');
        reverse(ret.begin(), ret.end());
        return ret;
    }
};
